package com.yanqu.road.server.cmd.strongholdwar;

import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.StrongholdWarCrossProto;
import com.yanqu.road.pb.activity.StrongholdWarProto;
import com.yanqu.road.server.cmd.CrossUnionCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.strongholdwar.StrongholdWarMgr;
import com.yanqu.road.server.manager.user.CrossUserMgr;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.utils.YanQuMessageUtils;

import java.util.Map;

@Cmd(code = CrossProtocol.C_CROSS_STRONGHOLD_DONATE_ITEM_DETAIL, desc = "")
public class CrossStrongholdMemberDonateItemDetailCmd extends CrossUnionCommand {
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        StrongholdWarCrossProto.StrongholdCrossDonateItemDetailReqMsg req = StrongholdWarCrossProto.StrongholdCrossDonateItemDetailReqMsg.parseFrom(packet.getBytes());
        int activityId = req.getActivityId();
        String unionUid = req.getUnionId();
        int type = req.getType();
        StrongholdWarProto.StrongholdMemberItemDonateDataRespMsg.Builder resp = StrongholdWarProto.StrongholdMemberItemDonateDataRespMsg.newBuilder();
        Map<Long, Integer> dataMap = StrongholdWarMgr.getMemberItemDonateList(activityId,unionUid,type);
        for (Map.Entry<Long, Integer> entry : dataMap.entrySet()) {
            Long userId = entry.getKey();
            Integer value = entry.getValue();
            StrongholdWarProto.ItemDonateDataMsg.Builder msg = StrongholdWarProto.ItemDonateDataMsg.newBuilder();
            msg.setUserInfo(PlayerBasePb.parsePlayerBaseTempMsg(CrossUserMgr.getUserBaseInfo(userId)));
            msg.setValue(String.valueOf(value));
            resp.addData(msg);
        }
        YanQuMessage message = YanQuMessageUtils.buildMessage(ClientProtocol.U_STRONGHOLD_WAR_MEMBER_ITEM_DONATE, resp);
        MessageHelper.sendPacket(serverId, packet.getPlayerId(), message);
    }

    @Override
    public void sendData() {

    }
}
